﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using DCSLibrary;
using System.Data;
using Utils.DatabaseUtils;
using System.Collections;
using Utils.DCSControl;
using Utils.Entity;
using Utils.DC.Web.UI;
using Utils;

public partial class Admin_MasterPage : System.Web.UI.MasterPage
{
    FunctionPageUI objFunctionPage = new FunctionPageUI();
    CategoryPageUI objCategoryPage = new CategoryPageUI();   
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            RadPanelItem item = null;

            RadPanelItem itemCap2 = null;

            //Lay ve cac trang admin
            DataSet dsAdmin = objFunctionPage.GetByType(true);

            //Lay ve tat ca cac trang category
            DataSet dsAdminCategoryPage = objCategoryPage.GetAll();
          
            DataTable dt = null;
            DataRow rowCap2 = null;
            IEnumerator ie = null;
            if (dsAdmin != null && dsAdmin.Tables.Count > 0)
            {
                DataTable dtVisibleAdmin = TableLib.CreateTable(dsAdmin.Tables[0], "IsVisible = 1");
                
                foreach (DataRow row in dtVisibleAdmin.Rows)
                {
                    item = new RadPanelItem(row["FunctionPageName"].ToString(), "#");
                    item.CssClass = "Menu";
                    AdminMenu.Items.Add(item);

                    dt = TableLib.CreateTable(dsAdminCategoryPage.Tables[0], "ParentID = " + row["FunctionPageID"].ToString() + " and IsVisible = 1");
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        ie = dt.Rows.GetEnumerator();
                        while (ie.MoveNext())
                        {
                            //TODO bo phan / trong link menu
                            rowCap2 = (DataRow)ie.Current;
                            itemCap2 = new RadPanelItem(rowCap2[1].ToString().Trim(), "/Admin/" + row["FunctionPageAlias"].ToString().Trim() + "/" + rowCap2["FunctionPageAlias"].ToString().Trim() + ".aspx");
                            item.Items.Add(itemCap2);

                        }
                    }
                }
            }
        }
    }
    

    protected void SignOut_Click(object sender, EventArgs e)
    {
        PageUtility.SighOut(Session);
        //TODO xoa standard
        Response.Redirect("/Admin/Default.aspx");
    }

    
    #region Cac ham thao tac du lieu


    #endregion

}
